Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.router = void 0;
var e = require("../../@babel/runtime/helpers/objectSpread2");
require("../../@babel/runtime/helpers/Arrayincludes");
var t = require("../config/index"),
  n = function () {
    var n = null,
      r = null,
      u = null,
      c = {
        switchTab: wx.switchTab,
        reLaunch: wx.reLaunch,
        redirectTo: wx.redirectTo,
        navigateTo: wx.navigateTo
      };

    function a() {
      var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
      return "?".concat(Object.keys(e).map((function (t) {
        return "".concat(t, "=").concat(e[t])
      })).join("&"))
    }

    function o(e, r) {
      return !!t.tabBarPages.includes(e) && (n = r || null, wx.switchTab({
        url: e,
        complete: function () {
          var e = setTimeout((function () {
            clearTimeout(e), i()
          }), 200)
        }
      }), !0)
    }

    function i() {
      n = null
    }
    return Object.keys(c).forEach((function (t) {
      Object.defineProperty(wx, t, {
        enumerable: !0,
        configurable: !0,
        get: function () {
          return function (n) {
            return function (t, n) {
              if ("function" == typeof u) {
                var r = $.getCurrentPage().route,
                  a = t.url;
                u(a, r, (function () {
                  return c[n](t)
                }), e(e({}, t), {}, {
                  type: n
                }))
              }
            }(n, t)
          }
        }
      })
    })), {
      beforeEach: function (e) {
        u = e
      },
      push: function (e, t) {
        o(e, t) || (r = t, wx.navigateTo({
          url: "".concat(e).concat(t ? a(t) : "")
        }))
      },
      replace: function (e, t) {
        o(e) || wx.redirectTo({
          url: "".concat(e).concat(t ? a(t) : "")
        })
      },
      back: function (e) {
        1 === getCurrentPages().length ? o(t.tabBarPages[0]) : (n = (null == e ? void 0 : e.params) || null, wx.navigateBack({
          delta: (null == e ? void 0 : e.delta) || 1,
          complete: function () {
            var e = setTimeout((function () {
              clearTimeout(e), i()
            }), 200)
          }
        }))
      },
      reLaunch: function (e, t) {
        wx.reLaunch({
          url: "".concat(e).concat(t ? a(t) : "")
        })
      },
      getParams: function () {
        return n
      },
      clearCurrentParams: i,
      useRouter: function () {
        var e = {
            setValue: function () {
              var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {
                to: "",
                from: "",
                next: function () {},
                interceptNext: function () {
                  return $.router.back()
                },
                params: {}
              };
              Object.keys(e).forEach((function (n) {
                t[n] = e[n]
              }))
            }
          },
          t = Object.create(e);
        return t.setValue(),
          function () {
            return t
          }
      }(),
      getNavigateParams: function () {
        return r
      }
    }
  }();
exports.router = n;